/*      */ package com.zimbra.cs.account.ldap;
/*      */ 
/*      */ import com.google.common.collect.Maps;
/*      */ import com.zimbra.common.account.Key.DomainBy;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.util.EmailUtil;
/*      */ import com.zimbra.common.util.Log;
/*      */ import com.zimbra.common.util.LogFactory;
/*      */ import com.zimbra.common.util.StringUtil;
/*      */ import com.zimbra.cs.account.Account;
/*      */ import com.zimbra.cs.account.AccountServiceException;
/*      */ import com.zimbra.cs.account.Alias;
/*      */ import com.zimbra.cs.account.Config;
/*      */ import com.zimbra.cs.account.DistributionList;
/*      */ import com.zimbra.cs.account.Domain;
/*      */ import com.zimbra.cs.account.DynamicGroup;
/*      */ import com.zimbra.cs.account.Entry;
/*      */ import com.zimbra.cs.account.Entry.EntryType;
/*      */ import com.zimbra.cs.account.NamedEntry;
/*      */ import com.zimbra.cs.account.NamedEntry.Visitor;
/*      */ import com.zimbra.cs.account.SearchDirectoryOptions;
/*      */ import com.zimbra.cs.account.SearchDirectoryOptions.ObjectType;
/*      */ import com.zimbra.cs.account.Server;
/*      */ import com.zimbra.cs.account.XMPPComponent;
/*      */ import com.zimbra.cs.account.ldap.entry.LdapEntry;
/*      */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*      */ import com.zimbra.cs.httpclient.URLUtil;
/*      */ import com.zimbra.cs.ldap.ILdapContext;
/*      */ import com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId;
/*      */ import com.zimbra.soap.admin.type.CacheEntryType;
/*      */ import java.util.HashMap;
/*      */ import java.util.HashSet;
/*      */ import java.util.Map;
/*      */ import java.util.Set;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class RenameDomain
/*      */ {
/*      */   public static abstract class RenameDomainLdapHelper
/*      */   {
/*      */     protected LdapProv mProv;
/*      */     protected ILdapContext mZlc;
/*      */     
/*      */     public RenameDomainLdapHelper(LdapProv prov, ILdapContext zlc)
/*      */     {
/*   62 */       this.mProv = prov;
/*   63 */       this.mZlc = zlc; }
/*      */     
/*      */     public abstract Account getAccountById(String paramString) throws ServiceException;
/*      */     
/*      */     public abstract DistributionList getDistributionListById(String paramString) throws ServiceException;
/*      */     
/*      */     public abstract DynamicGroup getDynamicGroupById(String paramString) throws ServiceException;
/*      */     
/*      */     public abstract void createEntry(String paramString, Map<String, Object> paramMap) throws ServiceException;
/*      */     
/*      */     public abstract void deleteEntry(String paramString) throws ServiceException;
/*      */     
/*      */     public abstract void renameEntry(String paramString1, String paramString2) throws ServiceException;
/*      */     
/*      */     public abstract void searchDirectory(SearchDirectoryOptions paramSearchDirectoryOptions, NamedEntry.Visitor paramVisitor) throws ServiceException;
/*      */     
/*      */     public abstract void modifyLdapAttrs(Entry paramEntry, Map<String, ? extends Object> paramMap) throws ServiceException;
/*      */     
/*      */     public abstract void renameAddressesInAllDistributionLists(Map<String, String> paramMap);
/*      */     
/*      */     public abstract void renameXMPPComponent(String paramString1, String paramString2) throws ServiceException; }
/*   84 */   private static final Log sRenameDomainLog = LogFactory.getLog("zimbra.provisioning.renamedomain");
/*      */   
/*      */   private final LdapProv mProv;
/*      */   private final RenameDomainLdapHelper mLdapHelper;
/*      */   private final Domain mOldDomain;
/*      */   private final String mOldDomainId;
/*      */   private final String mOldDomainName;
/*      */   private final String mNewDomainName;
/*      */   
/*      */   public RenameDomain(LdapProv prov, RenameDomainLdapHelper ldapHelper, Domain oldDomain, String newDomainName)
/*      */   {
/*   95 */     this.mProv = prov;
/*   96 */     this.mLdapHelper = ldapHelper;
/*   97 */     this.mOldDomain = oldDomain;
/*   98 */     this.mOldDomainId = this.mOldDomain.getId();
/*   99 */     this.mOldDomainName = this.mOldDomain.getName();
/*  100 */     this.mNewDomainName = newDomainName;
/*      */   }
/*      */   
/*      */   private RenameDomainVisitor getVisitor(RenamePhase phase) {
/*  104 */     return new RenameDomainVisitor(this.mProv, this.mLdapHelper, this.mOldDomainName, this.mNewDomainName, phase, null);
/*      */   }
/*      */   
/*      */   public void execute()
/*      */     throws ServiceException
/*      */   {
/*  110 */     debug("Renaming domain %s(%s) to %s", new Object[] { this.mOldDomainName, this.mOldDomainId, this.mNewDomainName });
/*      */     
/*  112 */     RenameInfo renameInfo = beginRenameDomain();
/*  113 */     RenamePhase startingPhase = renameInfo.phase();
/*  114 */     RenamePhase phase = RenamePhase.FIX_FOREIGN_DL_MEMBERS;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  119 */     Domain newDomain = createNewDomain();
/*  120 */     debug("new domain: %s(%s)", new Object[] { newDomain.getName(), newDomain.getId() });
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  129 */     phase = RenamePhase.RENAME_ENTRIES;
/*  130 */     if (phase.ordinal() >= startingPhase.ordinal()) {
/*  131 */       debug("Entering phase " + phase.toString(), new Object[0]);
/*      */       
/*  133 */       RenameDomainVisitor visitor = getVisitor(phase);
/*      */       
/*  135 */       SearchDirectoryOptions options = new SearchDirectoryOptions();
/*  136 */       options.setDomain(this.mOldDomain);
/*  137 */       options.setOnMaster(true);
/*  138 */       options.setFilterString(ZLdapFilterFactory.FilterId.RENAME_DOMAIN, null);
/*  139 */       options.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.accounts, SearchDirectoryOptions.ObjectType.resources, SearchDirectoryOptions.ObjectType.distributionlists, SearchDirectoryOptions.ObjectType.dynamicgroups });
/*      */       
/*  141 */       this.mLdapHelper.searchDirectory(options, visitor);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*  146 */     phase = RenamePhase.FIX_FOREIGN_ALIASES;
/*  147 */     if (phase.ordinal() >= startingPhase.ordinal()) {
/*  148 */       debug("Entering phase " + phase.toString(), new Object[0]);
/*  149 */       renameInfo.setPhase(phase);
/*  150 */       renameInfo.write(this.mProv, this.mOldDomain);
/*  151 */       RenameDomainVisitor visitor = getVisitor(phase);
/*      */       
/*  153 */       SearchDirectoryOptions options = new SearchDirectoryOptions();
/*  154 */       options.setDomain(this.mOldDomain);
/*  155 */       options.setOnMaster(true);
/*  156 */       options.setFilterString(ZLdapFilterFactory.FilterId.RENAME_DOMAIN, null);
/*  157 */       options.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.aliases });
/*  158 */       this.mLdapHelper.searchDirectory(options, visitor);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  168 */     phase = RenamePhase.FIX_FOREIGN_DL_MEMBERS;
/*  169 */     if (phase.ordinal() >= startingPhase.ordinal()) {
/*  170 */       debug("Entering phase " + phase.toString(), new Object[0]);
/*  171 */       renameInfo.setPhase(phase);
/*  172 */       renameInfo.write(this.mProv, this.mOldDomain);
/*  173 */       RenameDomainVisitor visitor = getVisitor(phase);
/*      */       
/*  175 */       SearchDirectoryOptions options = new SearchDirectoryOptions();
/*  176 */       options.setDomain(newDomain);
/*  177 */       options.setOnMaster(true);
/*  178 */       options.setFilterString(ZLdapFilterFactory.FilterId.RENAME_DOMAIN, null);
/*  179 */       options.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.accounts, SearchDirectoryOptions.ObjectType.resources, SearchDirectoryOptions.ObjectType.distributionlists });
/*  180 */       this.mLdapHelper.searchDirectory(options, visitor);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  186 */     debug("Deleting old domain %s(%s)", new Object[] { this.mOldDomainName, this.mOldDomainId });
/*      */     
/*  188 */     String curDefaultDomain = this.mProv.getConfig().getAttr("zimbraDefaultDomainName");
/*  189 */     this.mProv.deleteDomain(this.mOldDomainId);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  194 */     updateGlobalConfigSettings(curDefaultDomain);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  201 */     endRenameDomain(newDomain, this.mOldDomainId);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  206 */     fixupXMPPComponents();
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  211 */     flushCacheOnAllServers(CacheEntryType.account);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public static enum RenamePhase
/*      */   {
/*  219 */     RENAME_ENTRIES, 
/*  220 */     FIX_FOREIGN_ALIASES, 
/*  221 */     FIX_FOREIGN_DL_MEMBERS;
/*      */     
/*      */     private RenamePhase() {}
/*      */     
/*  225 */     public static RenamePhase fromString(String s) throws ServiceException { try { return valueOf(s);
/*      */       } catch (IllegalArgumentException e) {
/*  227 */         throw ServiceException.FAILURE("unknown phase: " + s, e);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private static class RenameInfo
/*      */   {
/*      */     private static final String SRC = "SRC";
/*      */     
/*      */     private static final String DEST = "DEST";
/*      */     
/*      */     private static final char COLON = ':';
/*      */     
/*      */     private static final char COMMA = ',';
/*      */     
/*      */     private final String mSrcDomainName;
/*      */     
/*      */     private final String mDestDomainName;
/*      */     
/*      */     private RenameDomain.RenamePhase mPhase;
/*      */     
/*      */     private final boolean mIsSrc;
/*      */     
/*      */ 
/*      */     private RenameInfo(String srcDomainName, String destDomainName, RenameDomain.RenamePhase phase)
/*      */     {
/*  255 */       this.mSrcDomainName = srcDomainName;
/*  256 */       this.mDestDomainName = destDomainName;
/*  257 */       this.mPhase = phase;
/*  258 */       this.mIsSrc = (srcDomainName == null);
/*      */     }
/*      */     
/*  261 */     String srcDomainName() { return this.mSrcDomainName; }
/*  262 */     String destDomainName() { return this.mDestDomainName; }
/*  263 */     RenameDomain.RenamePhase phase() { return this.mPhase; }
/*      */     
/*      */     public void setPhase(RenameDomain.RenamePhase phase) throws ServiceException {
/*  266 */       this.mPhase = phase;
/*      */     }
/*      */     
/*      */     private String encodeSrc() {
/*  270 */       return "SRC," + this.mPhase.toString() + ':' + this.mDestDomainName;
/*      */     }
/*      */     
/*      */     private String encodeDest() {
/*  274 */       return "DEST:" + this.mSrcDomainName;
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     static RenameInfo load(Domain domain, boolean expectingSrc)
/*      */       throws ServiceException
/*      */     {
/*  287 */       String renameInfo = domain.getAttr("zimbraDomainRenameInfo");
/*  288 */       if (StringUtil.isNullOrEmpty(renameInfo)) {
/*  289 */         RenameDomain.debug("RenameInfo.load: domain=%s(%s), %s=not set", new Object[] { domain.getName(), domain.getId(), "zimbraDomainRenameInfo" });
/*      */         
/*  291 */         return null;
/*      */       }
/*  293 */       RenameDomain.debug("RenameInfo.load: domain=%s(%s), %s=%s", new Object[] { domain.getName(), domain.getId(), "zimbraDomainRenameInfo", renameInfo });
/*      */       
/*      */ 
/*  296 */       int idx = renameInfo.indexOf(':');
/*  297 */       if (idx == -1) {
/*  298 */         throw ServiceException.FAILURE("invalid value in zimbraDomainRenameInfo: " + renameInfo + " missing " + ':', null);
/*      */       }
/*      */       
/*      */ 
/*  302 */       String statusPart = renameInfo.substring(0, idx);
/*  303 */       String domainName = renameInfo.substring(idx + 1);
/*  304 */       if (StringUtil.isNullOrEmpty(domainName)) {
/*  305 */         throw ServiceException.FAILURE("invalid value in zimbraDomainRenameInfo: " + renameInfo + " missing domain name", null);
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*  310 */       idx = statusPart.indexOf(',');
/*  311 */       String srcOrDest = statusPart;
/*  312 */       RenameDomain.RenamePhase phase = null;
/*  313 */       if (idx != -1) {
/*  314 */         srcOrDest = statusPart.substring(0, idx);
/*  315 */         phase = RenameDomain.RenamePhase.fromString(statusPart.substring(idx + 1));
/*      */       }
/*      */       
/*  318 */       if (srcOrDest.equals("SRC")) {
/*  319 */         if (!expectingSrc) {
/*  320 */           throw ServiceException.FAILURE("invalid value in zimbraDomainRenameInfo: " + renameInfo + " missing " + "DEST" + " keyword", null);
/*      */         }
/*      */         
/*      */ 
/*      */ 
/*  325 */         if (phase == null) {
/*  326 */           throw ServiceException.FAILURE("invalid value in zimbraDomainRenameInfo: " + renameInfo + " missing phase info for source domain", null);
/*      */         }
/*      */         
/*      */ 
/*      */ 
/*  331 */         return new RenameInfo(null, domainName, phase);
/*      */       }
/*  333 */       if (expectingSrc) {
/*  334 */         throw ServiceException.FAILURE("invalid value in zimbraDomainRenameInfo: " + renameInfo + " missing " + "SRC" + " keyword", null);
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*  339 */       return new RenameInfo(domainName, null, phase);
/*      */     }
/*      */     
/*      */     public void write(LdapProv prov, Domain domain) throws ServiceException
/*      */     {
/*  344 */       HashMap<String, Object> attrs = new HashMap();
/*      */       
/*      */       String renameInfoStr;
/*      */       String renameInfoStr;
/*  348 */       if (this.mIsSrc) {
/*  349 */         renameInfoStr = encodeSrc();
/*      */       } else
/*  351 */         renameInfoStr = encodeDest();
/*  352 */       attrs.put("zimbraDomainRenameInfo", renameInfoStr);
/*      */       
/*  354 */       RenameDomain.debug("RenameInfo.write: domain=%s(%s), %s=%s", new Object[] { domain.getName(), domain.getId(), "zimbraDomainRenameInfo", renameInfoStr });
/*      */       
/*  356 */       prov.modifyAttrs(domain, attrs);
/*      */     }
/*      */   }
/*      */   
/*      */   private RenameInfo beginRenameDomain()
/*      */     throws ServiceException
/*      */   {
/*  363 */     boolean domainIsShutdown = this.mOldDomain.isShutdown();
/*  364 */     RenameInfo renameInfo = RenameInfo.load(this.mOldDomain, true);
/*      */     
/*  366 */     if ((domainIsShutdown) && (renameInfo == null)) {
/*  367 */       throw ServiceException.INVALID_REQUEST("domain " + this.mOldDomainName + " is shutdown without rename domain info", null);
/*      */     }
/*      */     
/*      */ 
/*  371 */     if ((renameInfo != null) && (!renameInfo.destDomainName().equals(this.mNewDomainName))) {
/*  372 */       throw ServiceException.INVALID_REQUEST("domain " + this.mOldDomainName + " was being renamed to " + renameInfo.destDomainName() + " it cannot be renamed to " + this.mNewDomainName + " until the previous rename is finished", null);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  383 */     debug("Locking old domain %s(%s)", new Object[] { this.mOldDomainName, this.mOldDomainId });
/*  384 */     Map<String, String> attrs = new HashMap();
/*  385 */     attrs.put("zimbraDomainStatus", "shutdown");
/*  386 */     attrs.put("zimbraMailStatus", "disabled");
/*  387 */     this.mProv.modifyAttrs(this.mOldDomain, attrs, false, false);
/*      */     
/*  389 */     RenamePhase phase = RenamePhase.RENAME_ENTRIES;
/*      */     
/*  391 */     if (renameInfo == null)
/*      */     {
/*  393 */       renameInfo = new RenameInfo(null, this.mNewDomainName, phase, null);
/*  394 */       renameInfo.write(this.mProv, this.mOldDomain);
/*      */     }
/*      */     else {
/*  397 */       phase = renameInfo.phase();
/*      */     }
/*      */     
/*  400 */     flushCacheOnAllServers(CacheEntryType.domain);
/*      */     
/*  402 */     return renameInfo;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private Domain createNewDomain()
/*      */     throws ServiceException
/*      */   {
/*  411 */     Map<String, Object> domainAttrs = new HashMap(this.mOldDomain.getAttrs(false));
/*      */     
/*      */ 
/*  414 */     domainAttrs.remove("o");
/*  415 */     domainAttrs.remove("dc");
/*  416 */     domainAttrs.remove("objectClass");
/*      */     
/*      */ 
/*  419 */     domainAttrs.remove("zimbraId");
/*  420 */     domainAttrs.remove("zimbraDomainName");
/*  421 */     domainAttrs.remove("zimbraMailStatus");
/*      */     
/*      */ 
/*      */ 
/*  425 */     domainAttrs.remove("zimbraCreateTimestamp");
/*      */     
/*      */ 
/*  428 */     String curNotebookAcctName = (String)domainAttrs.get("zimbraNotebookAccount");
/*  429 */     String newNotebookAcctName = getNewAddress(curNotebookAcctName);
/*  430 */     if ((curNotebookAcctName != null) && (newNotebookAcctName != null)) {
/*  431 */       domainAttrs.remove("zimbraNotebookAccount");
/*  432 */       domainAttrs.put("zimbraNotebookAccount", newNotebookAcctName);
/*      */     }
/*      */     
/*      */ 
/*  436 */     domainAttrs.put("zimbraDomainStatus", "shutdown");
/*  437 */     domainAttrs.put("zimbraMailStatus", "disabled");
/*      */     
/*  439 */     Domain newDomain = null;
/*      */     try {
/*  441 */       debug("Creating new domain %s", new Object[] { this.mNewDomainName });
/*  442 */       newDomain = this.mProv.createDomain(this.mNewDomainName, domainAttrs);
/*      */     } catch (AccountServiceException e) {
/*  444 */       if (e.getCode().equals("account.DOMAIN_EXISTS")) {
/*  445 */         newDomain = this.mProv.get(Key.DomainBy.name, this.mNewDomainName);
/*  446 */         if (newDomain == null) {
/*  447 */           throw ServiceException.FAILURE("failed to load existing domain " + this.mNewDomainName, null);
/*      */         }
/*      */         
/*      */ 
/*  451 */         RenameInfo renameInfo = RenameInfo.load(newDomain, false);
/*      */         
/*  453 */         if (renameInfo == null)
/*      */         {
/*      */ 
/*  456 */           endRenameDomain(this.mOldDomain, null);
/*  457 */           throw ServiceException.INVALID_REQUEST("domain " + this.mNewDomainName + " already exists", null);
/*      */         }
/*      */         
/*  460 */         if (!renameInfo.srcDomainName().equals(this.mOldDomainName)) {
/*  461 */           throw ServiceException.INVALID_REQUEST("domain " + this.mNewDomainName + " was being renamed from " + renameInfo.srcDomainName() + " it cannot be renamed from " + this.mOldDomainName + " until the previous rename is finished", null);
/*      */         }
/*      */         
/*      */ 
/*      */ 
/*      */ 
/*  467 */         return newDomain;
/*      */       }
/*  469 */       throw e;
/*      */     }
/*      */     
/*      */ 
/*  473 */     RenameInfo renameInfo = new RenameInfo(this.mOldDomainName, null, null, null);
/*  474 */     renameInfo.write(this.mProv, newDomain);
/*  475 */     return newDomain;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private void endRenameDomain(Domain domain, String domainId)
/*      */     throws ServiceException
/*      */   {
/*  484 */     debug("endRenameDomain domain=%s(%s), domainId=%s", new Object[] { domain.getName(), domain.getId(), domainId == null ? "null" : domainId });
/*      */     
/*      */ 
/*  487 */     HashMap<String, Object> attrs = new HashMap();
/*  488 */     if (domainId != null)
/*  489 */       attrs.put("zimbraId", domainId);
/*  490 */     attrs.put("zimbraDomainRenameInfo", "");
/*  491 */     attrs.put("zimbraDomainStatus", "active");
/*  492 */     attrs.put("zimbraMailStatus", "enabled");
/*  493 */     this.mLdapHelper.modifyLdapAttrs(domain, attrs);
/*      */     
/*  495 */     flushCacheOnAllServers(CacheEntryType.domain);
/*      */   }
/*      */   
/*      */   static class RenameDomainVisitor implements NamedEntry.Visitor
/*      */   {
/*      */     private final LdapProv mProv;
/*      */     private final RenameDomain.RenameDomainLdapHelper mLdapHelper;
/*      */     private final String mOldDomainName;
/*      */     private final String mNewDomainName;
/*      */     private final RenameDomain.RenamePhase mPhase;
/*      */     private static final Set<String> sAddrContainsDomainOnly;
/*      */     
/*      */     static {
/*  508 */       sAddrContainsDomainOnly = new HashSet();
/*      */       
/*  510 */       sAddrContainsDomainOnly.add("zimbraMailCatchAllAddress");
/*  511 */       sAddrContainsDomainOnly.add("zimbraMailCatchAllCanonicalAddress");
/*  512 */       sAddrContainsDomainOnly.add("zimbraMailCatchAllForwardingAddress");
/*      */     }
/*      */     
/*  515 */     private static final String[] sDLAttrsNeedRename = { "mail", "zimbraMailAlias", "zimbraMailForwardingAddress", "zimbraMailDeliveryAddress", "zimbraMailCanonicalAddress", "zimbraMailCatchAllAddress", "zimbraMailCatchAllCanonicalAddress", "zimbraMailCatchAllForwardingAddress", "zimbraPrefAllowAddressForDelegatedSender" };
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  526 */     private static final String[] sAcctAttrsNeedRename = { "mail", "zimbraMailAlias", "zimbraMailForwardingAddress", "zimbraMailDeliveryAddress", "zimbraMailCanonicalAddress", "zimbraMailCatchAllAddress", "zimbraMailCatchAllCanonicalAddress", "zimbraMailCatchAllForwardingAddress", "zimbraPrefAllowAddressForDelegatedSender" };
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private static boolean addrContainsDomainOnly(String addr)
/*      */     {
/*  539 */       return sAddrContainsDomainOnly.contains(addr);
/*      */     }
/*      */     
/*      */     private RenameDomainVisitor(LdapProv prov, RenameDomain.RenameDomainLdapHelper ldapHelper, String oldDomainName, String newDomainName, RenameDomain.RenamePhase phase)
/*      */     {
/*  544 */       this.mProv = prov;
/*  545 */       this.mLdapHelper = ldapHelper;
/*  546 */       this.mOldDomainName = oldDomainName;
/*  547 */       this.mNewDomainName = newDomainName;
/*  548 */       this.mPhase = phase;
/*      */     }
/*      */     
/*      */     public void visit(NamedEntry entry) throws ServiceException
/*      */     {
/*  553 */       RenameDomain.debug("(" + this.mPhase.toString() + ") visiting " + entry.getName(), new Object[0]);
/*      */       
/*  555 */       if (this.mPhase == RenameDomain.RenamePhase.RENAME_ENTRIES) {
/*  556 */         handleEntry(entry);
/*  557 */       } else if (this.mPhase == RenameDomain.RenamePhase.FIX_FOREIGN_ALIASES) {
/*  558 */         if ((entry instanceof Alias)) {
/*  559 */           handleForeignAlias(entry);
/*      */         }
/*  561 */         else if (!$assertionsDisabled) throw new AssertionError();
/*  562 */       } else if (this.mPhase == RenameDomain.RenamePhase.FIX_FOREIGN_DL_MEMBERS) {
/*  563 */         handleForeignDLMembers(entry);
/*      */       }
/*      */     }
/*      */     
/*      */     private void handleEntry(NamedEntry entry) throws ServiceException {
/*  568 */       LdapEntry ldapEntry = (LdapEntry)entry;
/*  569 */       String[] parts = EmailUtil.getLocalPartAndDomain(entry.getName());
/*      */       
/*  571 */       Entry.EntryType entryType = entry.getEntryType();
/*      */       
/*  573 */       String newDn = null;
/*      */       try
/*      */       {
/*  576 */         if (Entry.EntryType.ACCOUNT == entryType) {
/*  577 */           newDn = this.mProv.getDIT().accountDNRename(ldapEntry.getDN(), parts[0], this.mNewDomainName);
/*  578 */         } else if (Entry.EntryType.DISTRIBUTIONLIST == entryType) {
/*  579 */           newDn = this.mProv.getDIT().distributionListDNRename(ldapEntry.getDN(), parts[0], this.mNewDomainName);
/*  580 */         } else if (Entry.EntryType.DYNAMICGROUP == entryType) {
/*  581 */           newDn = this.mProv.getDIT().dynamicGroupDNRename(ldapEntry.getDN(), parts[0], this.mNewDomainName);
/*      */         } else {
/*  583 */           RenameDomain.warn((Throwable)null, "handleEntry", "encountered invalid entry type", "entry=[%s]", new Object[] { entry.getName() });
/*  584 */           return;
/*      */         }
/*      */       } catch (ServiceException e) {
/*  587 */         RenameDomain.warn(e, "handleEntry", "cannot get new DN, entry not handled", "entry=[%s]", new Object[] { entry.getName() });
/*  588 */         return;
/*      */       }
/*      */       
/*      */ 
/*  592 */       String[] aliases = null;
/*      */       
/*  594 */       if (Entry.EntryType.ACCOUNT == entryType) {
/*  595 */         aliases = ((Account)entry).getAliases();
/*  596 */       } else if (Entry.EntryType.DISTRIBUTIONLIST == entryType) {
/*  597 */         aliases = ((DistributionList)entry).getAliases();
/*  598 */       } else if (Entry.EntryType.DYNAMICGROUP == entryType) {
/*  599 */         aliases = ((DynamicGroup)entry).getAliases();
/*      */       } else {
/*  601 */         RenameDomain.warn((Throwable)null, "handleEntry", "encountered invalid entry type", "entry=[%s]", new Object[] { entry.getName() });
/*      */         
/*  603 */         return;
/*      */       }
/*  605 */       handleAliases(entry, aliases, newDn);
/*      */       
/*      */ 
/*      */ 
/*  609 */       String oldDn = ((LdapEntry)entry).getDN();
/*  610 */       moveEntry(entry, oldDn, newDn);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private void handleAliases(NamedEntry targetEntry, String[] aliases, String newTargetDn)
/*      */     {
/*  617 */       LdapEntry ldapEntry = (LdapEntry)targetEntry;
/*  618 */       String oldDn = ldapEntry.getDN();
/*      */       
/*      */ 
/*  621 */       for (int i = 0; i < aliases.length; i++)
/*      */       {
/*      */ 
/*      */ 
/*      */ 
/*  626 */         if (!aliases[i].equals(targetEntry.getName()))
/*      */         {
/*      */ 
/*  629 */           String[] parts = EmailUtil.getLocalPartAndDomain(aliases[i]);
/*  630 */           if (parts == null) {
/*  631 */             if (!$assertionsDisabled) throw new AssertionError();
/*  632 */             RenameDomain.warn("moveEntry", "encountered invalid alias address", "alias=[%s], entry=[%s]", new Object[] { aliases[i], targetEntry.getName() });
/*      */           }
/*      */           else
/*      */           {
/*  636 */             String aliasLocal = parts[0];
/*  637 */             String aliasDomain = parts[1];
/*  638 */             if (aliasDomain.equals(this.mOldDomainName))
/*      */             {
/*      */ 
/*      */ 
/*  642 */               String oldAliasDn = "";
/*  643 */               String newAliasDn = "";
/*      */               try {
/*  645 */                 oldAliasDn = this.mProv.getDIT().aliasDN(oldDn, this.mOldDomainName, aliasLocal, this.mOldDomainName);
/*  646 */                 newAliasDn = this.mProv.getDIT().aliasDNRename(newTargetDn, this.mNewDomainName, aliasLocal + "@" + this.mNewDomainName);
/*  647 */                 if (!oldAliasDn.equals(newAliasDn)) {
/*  648 */                   this.mLdapHelper.renameEntry(oldAliasDn, newAliasDn);
/*      */                 }
/*      */               }
/*      */               catch (ServiceException e) {
/*  652 */                 RenameDomain.warn(e, "moveEntry", "alias not moved", "alias=[%s], entry=[%s], oldAliasDn=[%s], newAliasDn=[%s]", new Object[] { aliases[i], targetEntry.getName(), oldAliasDn, newAliasDn });
/*      */               }
/*      */             }
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*      */     private void moveEntry(NamedEntry entry, String oldDn, String newDn) {
/*  661 */       Entry.EntryType entryType = entry.getEntryType();
/*  662 */       String entryId = entry.getId();
/*      */       
/*  664 */       NamedEntry refreshedEntry = null;
/*      */       
/*  666 */       if (!oldDn.equals(newDn))
/*      */       {
/*      */         try {
/*  669 */           this.mLdapHelper.renameEntry(oldDn, newDn);
/*      */         } catch (ServiceException e) {
/*  671 */           RenameDomain.warn(e, "moveEntry", "renameEntry failed", "entry=[%s], oldDn=[%s], newDn=[%s]", new Object[] { entry.getName(), oldDn, newDn });
/*      */         }
/*      */         
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */         try
/*      */         {
/*  681 */           if (Entry.EntryType.ACCOUNT == entryType) {
/*  682 */             refreshedEntry = this.mLdapHelper.getAccountById(entryId);
/*  683 */           } else if (Entry.EntryType.DISTRIBUTIONLIST == entryType) {
/*  684 */             refreshedEntry = this.mLdapHelper.getDistributionListById(entryId);
/*  685 */           } else if (Entry.EntryType.DYNAMICGROUP == entryType) {
/*  686 */             refreshedEntry = this.mLdapHelper.getDynamicGroupById(entryId);
/*      */           }
/*      */         } catch (ServiceException e) {
/*  689 */           RenameDomain.warn(e, "moveEntry", "failed to get entry by id after move, entry not modified", "entry=[%s], oldDn=[%s], newDn=[%s]", new Object[] { entry.getName(), oldDn, newDn });
/*      */           
/*      */ 
/*  692 */           return;
/*      */         }
/*      */       }
/*      */       
/*  696 */       if (refreshedEntry == null) {
/*  697 */         RenameDomain.warn((Throwable)null, "moveEntry", "entry not found after rename, entry not modified", "entry=[%s], oldDn=[%s], newDn=[%s]", new Object[] { entry.getName(), oldDn, newDn });
/*      */         
/*  699 */         return;
/*      */       }
/*      */       
/*      */ 
/*  703 */       Map<String, Object> fixedAttrs = fixupAddrs(entry, sDLAttrsNeedRename);
/*      */       
/*      */       try
/*      */       {
/*  707 */         this.mLdapHelper.modifyLdapAttrs(refreshedEntry, fixedAttrs);
/*      */       } catch (ServiceException e) {
/*  709 */         RenameDomain.warn(e, "moveEntry", "modifyAttrsInternal", "entry=[%s], oldDn=[%s], newDn=[%s]", new Object[] { entry.getName(), oldDn, newDn });
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */     private Map<String, Object> fixupAddrs(NamedEntry entry, String[] attrsNeedRename)
/*      */     {
/*  717 */       Map<String, Object> attrs = Maps.newHashMap(entry.getAttrs(false));
/*      */       
/*      */ 
/*  720 */       if ((entry instanceof DynamicGroup)) {
/*  721 */         attrs.remove("member");
/*      */       }
/*      */       
/*  724 */       for (String attr : attrsNeedRename) {
/*  725 */         boolean addrCanBeDomainOnly = addrContainsDomainOnly(attr);
/*      */         
/*  727 */         String[] values = entry.getMultiAttr(attr, false);
/*  728 */         if (values.length > 0) {
/*  729 */           Set<String> newValues = new HashSet();
/*  730 */           for (int i = 0; i < values.length; i++) {
/*  731 */             String newValue = convertToNewAddr(values[i], this.mOldDomainName, this.mNewDomainName, addrCanBeDomainOnly);
/*      */             
/*  733 */             if (newValue != null) {
/*  734 */               newValues.add(newValue);
/*      */             }
/*      */           }
/*      */           
/*      */ 
/*      */ 
/*      */ 
/*  741 */           if (newValues.size() > 0) {
/*  742 */             attrs.put(attr, newValues.toArray(new String[newValues.size()]));
/*      */           }
/*      */         }
/*      */       }
/*      */       
/*  747 */       return attrs;
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private String convertToNewAddr(String address, String oldDomain, String newDomain, boolean addrCanBeDomainOnly)
/*      */     {
/*  760 */       String addr = address.trim();
/*  761 */       String[] parts = EmailUtil.getLocalPartAndDomain(addr);
/*  762 */       if ((parts == null) && (!addrCanBeDomainOnly)) {
/*  763 */         RenameDomain.warn("convertToNewAddr", "encountered invalid address", "addr=[%s]", new Object[] { addr });
/*  764 */         return null;
/*      */       }
/*      */       
/*  767 */       String local = null;
/*  768 */       String domain = null;
/*      */       
/*  770 */       if (parts != null) {
/*  771 */         local = parts[0];
/*  772 */         domain = parts[1];
/*      */       }
/*  774 */       else if (addr.charAt(0) == '@') {
/*  775 */         domain = addr.substring(1);
/*      */       }
/*      */       
/*      */ 
/*  779 */       if (domain == null) {
/*  780 */         RenameDomain.warn("convertToNewAddr", "encountered invalid address", "addr=[%s]", new Object[] { addr });
/*  781 */         return null;
/*      */       }
/*      */       
/*  784 */       if (domain.equals(oldDomain)) {
/*  785 */         if (local != null) {
/*  786 */           return local + "@" + newDomain;
/*      */         }
/*  788 */         return "@" + newDomain;
/*      */       }
/*      */       
/*  791 */       return addr;
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */     private void handleForeignAlias(NamedEntry entry)
/*      */     {
/*  799 */       Alias alias = (Alias)entry;
/*  800 */       NamedEntry targetEntry = null;
/*      */       try {
/*  802 */         targetEntry = this.mProv.searchAliasTarget(alias, false);
/*      */       } catch (ServiceException e) {
/*  804 */         RenameDomain.warn(e, "handleForeignAlias", "target entry not found for aliasalias=[%s], target=[%s]", alias.getName(), new Object[] { alias.getAttr("zimbraAliasTargetId") });
/*      */         
/*  806 */         return;
/*      */       }
/*      */       
/*      */ 
/*  810 */       if (targetEntry == null) {
/*  811 */         RenameDomain.warn("handleForeignAlias", "encountered orphan alias", "alias=[%s]", new Object[] { alias.getName() });
/*  812 */         return;
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*  817 */       String targetName = targetEntry.getName();
/*  818 */       String[] targetParts = EmailUtil.getLocalPartAndDomain(targetName);
/*  819 */       if (targetParts == null) {
/*  820 */         RenameDomain.warn("handleForeignAlias", "encountered invalid alias target address", "target=[%s]", new Object[] { targetName });
/*  821 */         return;
/*      */       }
/*  823 */       String targetDomain = targetParts[1];
/*  824 */       if (!targetDomain.equals(this.mOldDomainName)) {
/*  825 */         String aliasOldAddr = alias.getName();
/*  826 */         String[] aliasParts = EmailUtil.getLocalPartAndDomain(aliasOldAddr);
/*  827 */         if (aliasParts == null) {
/*  828 */           RenameDomain.warn("handleForeignAlias", "encountered invalid alias address", "alias=[%s]", new Object[] { aliasOldAddr });
/*  829 */           return;
/*      */         }
/*  831 */         String aliasLocal = aliasParts[0];
/*  832 */         String aliasNewAddr = aliasLocal + "@" + this.mNewDomainName;
/*  833 */         if ((targetEntry instanceof DistributionList)) {
/*  834 */           DistributionList dl = (DistributionList)targetEntry;
/*  835 */           fixupForeignTarget(dl, aliasOldAddr, aliasNewAddr);
/*  836 */         } else if ((targetEntry instanceof Account)) {
/*  837 */           Account acct = (Account)targetEntry;
/*  838 */           fixupForeignTarget(acct, aliasOldAddr, aliasNewAddr);
/*  839 */         } else if ((targetEntry instanceof DynamicGroup)) {
/*  840 */           DynamicGroup dynGroup = (DynamicGroup)targetEntry;
/*  841 */           fixupForeignTarget(dynGroup, aliasOldAddr, aliasNewAddr);
/*      */         } else {
/*  843 */           RenameDomain.warn("handleForeignAlias", "encountered invalid alias target type", "target=[%s]", new Object[] { targetName });
/*  844 */           return;
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*      */     private void fixupForeignTarget(DistributionList targetEntry, String aliasOldAddr, String aliasNewAddr)
/*      */     {
/*      */       try {
/*  852 */         this.mProv.removeAlias(targetEntry, aliasOldAddr);
/*      */       } catch (ServiceException e) {
/*  854 */         RenameDomain.warn("fixupTargetInOtherDomain", "cannot remove alias for dldl=[%s], aliasOldAddr=[%s], aliasNewAddr=[%s]", targetEntry.getName(), new Object[] { aliasOldAddr, aliasNewAddr });
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */       try
/*      */       {
/*  861 */         this.mProv.addAlias(targetEntry, aliasNewAddr);
/*      */       } catch (ServiceException e) {
/*  863 */         RenameDomain.warn("fixupTargetInOtherDomain", "cannot add alias for dldl=[%s], aliasOldAddr=[%s], aliasNewAddr=[%s]", targetEntry.getName(), new Object[] { aliasOldAddr, aliasNewAddr });
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */     private void fixupForeignTarget(DynamicGroup targetEntry, String aliasOldAddr, String aliasNewAddr)
/*      */     {
/*      */       try
/*      */       {
/*  872 */         this.mProv.removeGroupAlias(targetEntry, aliasOldAddr);
/*      */       } catch (ServiceException e) {
/*  874 */         RenameDomain.warn("fixupTargetInOtherDomain", "cannot remove alias for dynamic groupgroup=[%s], aliasOldAddr=[%s], aliasNewAddr=[%s]", targetEntry.getName(), new Object[] { aliasOldAddr, aliasNewAddr });
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */       try
/*      */       {
/*  881 */         this.mProv.addGroupAlias(targetEntry, aliasNewAddr);
/*      */       } catch (ServiceException e) {
/*  883 */         RenameDomain.warn("fixupTargetInOtherDomain", "cannot add alias for dynamic groupgroup=[%s], aliasOldAddr=[%s], aliasNewAddr=[%s]", targetEntry.getName(), new Object[] { aliasOldAddr, aliasNewAddr });
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */     private void fixupForeignTarget(Account targetEntry, String aliasOldAddr, String aliasNewAddr)
/*      */     {
/*      */       try
/*      */       {
/*  892 */         this.mProv.removeAlias(targetEntry, aliasOldAddr);
/*      */       } catch (ServiceException e) {
/*  894 */         RenameDomain.warn("fixupTargetInOtherDomain", "cannot remove alias for accountacct=[%s], aliasOldAddr=[%s], aliasNewAddr=[%s]", targetEntry.getName(), new Object[] { aliasOldAddr, aliasNewAddr });
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */       try
/*      */       {
/*  901 */         this.mProv.addAlias(targetEntry, aliasNewAddr);
/*      */       } catch (ServiceException e) {
/*  903 */         RenameDomain.warn("fixupTargetInOtherDomain", "cannot add alias for accountacct=[%s], aliasOldAddr=[%s], aliasNewAddr=[%s]", targetEntry.getName(), new Object[] { aliasOldAddr, aliasNewAddr });
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     private void handleForeignDLMembers(NamedEntry entry)
/*      */     {
/*  914 */       Map<String, String> changedPairs = new HashMap();
/*      */       
/*  916 */       String entryAddr = entry.getName();
/*  917 */       String[] oldNewPair = changedAddrPairs(entryAddr);
/*  918 */       if (oldNewPair != null) {
/*  919 */         changedPairs.put(oldNewPair[0], oldNewPair[1]);
/*      */       }
/*  921 */       String[] aliasesAddrs = entry.getMultiAttr("zimbraMailAlias", false);
/*  922 */       for (String aliasAddr : aliasesAddrs) {
/*  923 */         oldNewPair = changedAddrPairs(aliasAddr);
/*  924 */         if (oldNewPair != null) {
/*  925 */           changedPairs.put(oldNewPair[0], oldNewPair[1]);
/*      */         }
/*      */       }
/*  928 */       this.mLdapHelper.renameAddressesInAllDistributionLists(changedPairs);
/*      */     }
/*      */     
/*      */     private String[] changedAddrPairs(String addr) {
/*  932 */       String[] parts = EmailUtil.getLocalPartAndDomain(addr);
/*  933 */       if (parts == null) {
/*  934 */         RenameDomain.warn("changedAddrPairs", "encountered invalid address", "addr=[%s]", new Object[] { addr });
/*  935 */         return null;
/*      */       }
/*      */       
/*  938 */       String domain = parts[1];
/*  939 */       if (!domain.equals(this.mNewDomainName)) {
/*  940 */         return null;
/*      */       }
/*  942 */       String localPart = parts[0];
/*  943 */       String[] oldNewAddrPairs = new String[2];
/*  944 */       oldNewAddrPairs[0] = (localPart + "@" + this.mOldDomainName);
/*  945 */       oldNewAddrPairs[1] = (localPart + "@" + this.mNewDomainName);
/*      */       
/*  947 */       return oldNewAddrPairs;
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private String getNewAddress(String addr)
/*      */   {
/*  963 */     if (addr != null) {
/*  964 */       String[] parts = EmailUtil.getLocalPartAndDomain(addr);
/*  965 */       if (parts == null) {
/*  966 */         warn("getNewAccountName", "encountered invalid address", "addr=[%s]", new Object[] { addr });
/*  967 */         return null;
/*      */       }
/*      */       
/*  970 */       String localPart = parts[0];
/*  971 */       String domain = parts[1];
/*  972 */       if (!domain.equals(this.mOldDomainName)) {
/*  973 */         return null;
/*      */       }
/*  975 */       return localPart + "@" + this.mNewDomainName;
/*      */     }
/*  977 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private String getNewDomain(String domainName)
/*      */   {
/*  989 */     if (domainName != null) {
/*  990 */       if (!domainName.equals(this.mOldDomainName)) {
/*  991 */         return null;
/*      */       }
/*  993 */       return this.mNewDomainName;
/*      */     }
/*  995 */     return null;
/*      */   }
/*      */   
/*      */   private void updateSystemAccount(Entry entry, String attrName, Map<String, Object> attrMap) {
/*  999 */     String curAddr = entry.getAttr(attrName);
/* 1000 */     String newAddr = getNewAddress(curAddr);
/* 1001 */     if ((curAddr != null) && (newAddr != null)) {
/* 1002 */       attrMap.put(attrName, newAddr);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */   private void updateGlobalConfigSettings(String curDefaultDomainName)
/*      */   {
/*      */     try
/*      */     {
/* 1011 */       Config config = this.mProv.getConfig();
/*      */       
/* 1013 */       HashMap<String, Object> attrMap = new HashMap();
/* 1014 */       updateSystemAccount(config, "zimbraNotebookAccount", attrMap);
/* 1015 */       updateSystemAccount(config, "zimbraSpamIsSpamAccount", attrMap);
/* 1016 */       updateSystemAccount(config, "zimbraSpamIsNotSpamAccount", attrMap);
/* 1017 */       updateSystemAccount(config, "zimbraAmavisQuarantineAccount", attrMap);
/*      */       
/* 1019 */       String newDomainName = getNewDomain(curDefaultDomainName);
/* 1020 */       if ((curDefaultDomainName != null) && (newDomainName != null)) {
/* 1021 */         attrMap.put("zimbraDefaultDomainName", newDomainName);
/*      */       }
/* 1023 */       this.mProv.modifyAttrs(config, attrMap);
/* 1024 */       flushCacheOnAllServers(CacheEntryType.config);
/*      */     }
/*      */     catch (ServiceException e)
/*      */     {
/* 1028 */       warn("failed to update system accounts on global config", e);
/*      */     }
/*      */   }
/*      */   
/*      */   private void fixupXMPPComponents() throws ServiceException
/*      */   {
/* 1034 */     int domainLen = this.mOldDomainName.length();
/*      */     
/* 1036 */     for (XMPPComponent xmpp : this.mProv.getAllXMPPComponents()) {
/* 1037 */       if (this.mOldDomainId.equals(xmpp.getDomainId())) {
/* 1038 */         String curName = xmpp.getName();
/* 1039 */         if (curName.endsWith(this.mOldDomainName)) {
/* 1040 */           String newName = curName.substring(0, curName.length() - domainLen) + this.mNewDomainName;
/* 1041 */           debug("Renaming XMPP component " + curName + " to " + newName, new Object[0]);
/* 1042 */           this.mLdapHelper.renameXMPPComponent(xmpp.getId(), newName);
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void flushCacheOnAllServers(CacheEntryType type) throws ServiceException {
/* 1049 */     SoapProvisioning soapProv = new SoapProvisioning();
/* 1050 */     String adminUrl = null;
/*      */     
/* 1052 */     for (Server server : this.mProv.getAllMailClientServers())
/*      */     {
/*      */       try {
/* 1055 */         adminUrl = URLUtil.getAdminURL(server, "/service/admin/soap/", true);
/*      */       } catch (ServiceException e) {
/* 1057 */         warn(e, "flushCacheOnAllServers", "", "type=[%s]", new Object[] { type }); }
/* 1058 */       continue;
/*      */       
/*      */ 
/* 1061 */       soapProv.soapSetURI(adminUrl);
/*      */       try
/*      */       {
/* 1064 */         soapProv.soapZimbraAdminAuthenticate();
/* 1065 */         soapProv.flushCache(type, null);
/*      */       }
/*      */       catch (ServiceException e) {
/* 1068 */         warn(e, "flushCacheOnAllServers", "", "type=[%s] server=[%s]", new Object[] { type, server.getName() });
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private static void warn(Object o, Throwable t) {
/* 1074 */     sRenameDomainLog.warn(o, t);
/*      */   }
/*      */   
/*      */   private static void warn(String funcName, String desc, String format, Object... objects) {
/* 1078 */     warn(null, funcName, desc, format, objects);
/*      */   }
/*      */   
/*      */   private static void warn(Throwable t, String funcName, String desc, String format, Object... objects) {
/* 1082 */     if (sRenameDomainLog.isWarnEnabled())
/* 1083 */       sRenameDomainLog.warn(String.format(funcName + "(" + desc + "):" + format, objects), t);
/*      */   }
/*      */   
/*      */   private static void debug(String format, Object... objects) {
/* 1087 */     if (sRenameDomainLog.isDebugEnabled())
/* 1088 */       sRenameDomainLog.debug(String.format(format, objects));
/*      */   }
/*      */   
/*      */   private static void info(String format, Object... objects) {
/* 1092 */     sRenameDomainLog.info(String.format(format, objects));
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/RenameDomain.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */